package com.sphd.emanu.activity.topup;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sphd.emanu.R;
import com.sphd.emanu.adapter.TopUpTodaydapter;
import com.sphd.emanu.config.Constant;
import com.sphd.emanu.mvp.MVPBaseActivity;
import com.sphd.emanu.pojo.DayDepositSale;
import com.sphd.emanu.pojo.login.User;
import com.sphd.emanu.pojo.vip.MemDeposit;
import com.wzutils.TimeUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 充值 很日和月
 *
 * @Author Hu
 * @Time 2017/4/5 -- 16:25.
 * @Email 87683202@qq.com
 */
public class TopUpTodayActivity extends MVPBaseActivity<TopupContract.View, TopupPresenter> implements TopupContract.View {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.layout_topup_today)
    TextView layoutTopupToday;
    Intent intent;
    Bundle bundle;
    User user;

    @BindView(R.id.my_recycler)
    RecyclerView myRecycler;
    @BindView(R.id.my_swf)
    SwipeRefreshLayout mySwf;
    TopUpTodaydapter topUpTodaydapter;
    DayDepositSale dayDepositSale;
    int type;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_top_up);
        ButterKnife.bind(this);
        initView();
        initAdapter();
        initEvent();
    }

    private void initEvent() {
        mySwf.setOnRefreshListener(() -> addData());
        toolbar.setNavigationOnClickListener(v -> finish());
    }

    private void initAdapter() {
        setRefresh(mySwf);
        setRecy(myRecycler);
        topUpTodaydapter = new TopUpTodaydapter(R.layout.item_topup_today_order, new ArrayList<MemDeposit>(), context);
        if (null != topUpTodaydapter.getEmptyView()) {
            topUpTodaydapter.setEmptyView(emptyView);
        }
        myRecycler.setAdapter(topUpTodaydapter);
    }

    private void initView() {
        setTitleBar(toolbar, "今日充值");
        intent = getIntent();
        bundle = intent.getExtras();
        user = (User) bundle.getSerializable(Constant.USER_ENTITY);
        type = bundle.getInt(Constant.TYPE);
        if (type == 1) {
            dayDepositSale = (DayDepositSale) bundle.getSerializable(Constant.DAY_DEPOSIT_SALE);
        }
        addData();

    }

    private void addData() {
        showProgressDialog();
        mPresenter.saleDayDepositSum(user.getOid(), type == 0 ? null : TimeUtils.longToString(TimeUtils.dateToLong(dayDepositSale.getDate()), TimeUtils.YEAR_MONTH_DAY_HOUR_MIN_SS));
    }

    @Override
    public void recBean(DayDepositSale dayDepositSale) {
        dissProgressDialog();
        layoutTopupToday.setText("今日充值共计" + dayDepositSale.getNumber() + "人，共计" + dayDepositSale.getDepositSum() + "元");
        topUpTodaydapter.setNewData(dayDepositSale.getList());
    }
}
